package common;

import day002.Code04_ReverseList;

import java.util.Arrays;

public class Utils {


    //交换数组上i,j位置上的数据
    public static void swap(int[] arr, int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    // for test
    public static int[] generateRandomArray(int maxSize, int maxValue){
        int[] arr = new int[(int)((maxSize + 1) * Math.random())];
        for(int i = 0; i < arr.length; i++){
            arr[i] = (int)((maxValue + 1)* Math.random()) - (int)(maxValue * Math.random());
        }
        return arr;
    }

    public static void compareArr(int[] arr){
        Arrays.sort(arr);
    }

    public static int[] copyArray(int[] arr){
        if(arr == null){
            return null;
        }
        int[] res = new int[arr.length];
        for(int i = 0; i < arr.length; i++){
            res[i] = arr[i];
        }
        return res;
    }

    public static void printArr(int[] arr){

        System.out.println(Arrays.toString(arr));
    }
}
